<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>并发编程与多线程技术深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            transition: all 0.3s ease;
        }
        
        .content-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 8px;
            padding: 20px;
            overflow-x: auto;
            position: relative;
        }
        
        .code-block::before {
            content: 'Java';
            position: absolute;
            top: 10px;
            right: 10px;
            font-size: 12px;
            color: #666;
            background: #2d2d2d;
            padding: 2px 8px;
            border-radius: 4px;
        }
        
        .highlight-box {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            color: white;
            padding: 20px;
            border-radius: 12px;
            margin: 20px 0;
        }
        
        .feature-card {
            background: white;
            border-radius: 12px;
            padding: 24px;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
            transition: all 0.3s ease;
            border: 1px solid #e5e7eb;
        }
        
        .feature-card:hover {
            transform: translateY(-4px);
            box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
            border-color: #667eea;
        }
        
        .drop-cap {
            float: left;
            font-size: 4em;
            line-height: 0.8;
            margin: 0 8px 0 0;
            font-weight: 700;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-family: 'Noto Serif SC', serif;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 40px 0;
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .animate-fade-in {
            animation: fadeInUp 0.6s ease-out;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto text-center animate-fade-in">
            <h1 class="text-5xl md:text-6xl font-bold mb-6" style="font-family: 'Noto Serif SC', serif;">
                并发编程与多线程技术
            </h1>
            <p class="text-xl md:text-2xl opacity-90 max-w-3xl mx-auto leading-relaxed">
                探索现代程序设计的核心技术，掌握高性能应用开发的关键
            </p>
            <div class="mt-10 flex justify-center space-x-8">
                <div class="text-center">
                    <i class="fas fa-microchip text-4xl mb-2"></i>
                    <p class="text-sm">多核优化</p>
                </div>
                <div class="text-center">
                    <i class="fas fa-shield-alt text-4xl mb-2"></i>
                    <p class="text-sm">线程安全</p>
                </div>
                <div class="text-center">
                    <i class="fas fa-tachometer-alt text-4xl mb-2"></i>
                    <p class="text-sm">高性能</p>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="max-w-6xl mx-auto px-6 py-12">
        
        <!-- Introduction -->
        <div class="content-card rounded-2xl shadow-xl p-8 md:p-12 mb-12">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">并</span>发编程是现代程序设计中的一个重要领域，它允许程序同时执行多个任务，从而提升应用程序的性能和响应能力。多线程编程是实现并发编程的一种常用技术，尤其在处理高并发请求和计算密集型任务时，它能显著提升程序的效率。然而，编写并发程序并不容易，特别是在多线程环境下，如何确保线程安全、避免死锁和竞态条件，成为了程序员面临的重要问题。
            </p>
        </div>

        <!-- Concept Visualization -->
        <div class="content-card rounded-2xl shadow-xl p-8 mb-12">
            <h2 class="text-3xl font-bold mb-6 text-gray-800">
                <i class="fas fa-sitemap text-purple-600 mr-3"></i>
                核心概念关系图
            </h2>
            <div class="mermaid">
                graph TD
                    A[并发编程] --> B[多线程]
                    A --> C[多进程]
                    A --> D[异步编程]
                    B --> E[线程创建]
                    B --> F[线程同步]
                    B --> G[线程池]
                    F --> H[synchronized]
                    F --> I[Lock机制]
                    F --> J[原子操作]
                    B --> K[线程安全问题]
                    K --> L[死锁]
                    K --> M[竞态条件]
                    K --> N[内存一致性]
                    
                    style A fill:#667eea,stroke:#fff,stroke-width:3px,color:#fff
                    style B fill:#764ba2,stroke:#fff,stroke-width:3px,color:#fff
                    style K fill:#f093fb,stroke:#fff,stroke-width:3px,color:#fff
            </div>
        </div>

        <!-- Section 1: Basic Concepts -->
        <div class="grid md:grid-cols-2 gap-8 mb-12">
            <div class="feature-card">
                <h3 class="section-title text-2xl font-bold mb-4 text-gray-800">
                    <i class="fas fa-layer-group text-purple-600 mr-2"></i>
                    并发的定义
                </h3>
                <p class="text-gray-600 leading-relaxed">
                    并发指的是一个程序能够在多个任务之间进行切换执行，给用户带来"同时执行"的错觉。并发并不要求任务真正同时执行，而是能够有效地在多个任务之间切换，利用 CPU 的空闲时间来执行其他任务，进而提升系统的吞吐量和响应速度。
                </p>
            </div>
            
            <div class="feature-card">
                <h3 class="section-title text-2xl font-bold mb-4 text-gray-800">
                    <i class="fas fa-code-branch text-purple-600 mr-2"></i>
                    多线程的定义
                </h3>
                <p class="text-gray-600 leading-relaxed">
                    多线程是并发编程的一种实现方式。一个进程可以包含多个线程，每个线程都是程序中的独立执行单元，线程之间共享同一进程的资源。多线程能够充分利用多核 CPU 的优势，实现更高效的任务处理。
                </p>
            </div>
        </div>

        <!-- Section 2: Advantages and Challenges -->
        <div class="content-card rounded-2xl shadow-xl p-8 md:p-12 mb-12">
            <h2 class="text-3xl font-bold mb-8 text-gray-800">
                <i class="fas fa-balance-scale text-purple-600 mr-3"></i>
                多线程的优势与挑战
            </h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <h3 class="text-xl font-semibold mb-4 text-green-600">
                        <i class="fas fa-check-circle mr-2"></i>优势
                    </h3>
                    <div class="space-y-3">
                        <div class="flex items-start">
                            <i class="fas fa-bolt text-green-500 mt-1 mr-3"></i>
                            <div>
                                <strong>提高响应性：</strong>在多线程环境下，程序能够同时处理多个任务，避免了阻塞的情况。
                            </div>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-chart-line text-green-500 mt-1 mr-3"></i>
                            <div>
                                <strong>提高资源利用率：</strong>多线程能够充分利用多核 CPU，进行任务的并行处理。
                            </div>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-rocket text-green-500 mt-1 mr-3"></i>
                            <div>
                                <strong>提高吞吐量：</strong>在处理大量 I/O 密集型任务时，多线程能够有效地减少等待时间。
                            </div>
                        </div>
                    </div>
                </div>
                
                <div>
                    <h3 class="text-xl font-semibold mb-4 text-red-600">
                        <i class="fas fa-exclamation-triangle mr-2"></i>挑战
                    </h3>
                    <div class="space-y-3">
                        <div class="flex items-start">
                            <i class="fas fa-lock text-red-500 mt-1 mr-3"></i>
                            <div>
                                <strong>线程安全问题：</strong>多个线程共享同一资源时，可能会导致资源竞争。
                            </div>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-ban text-red-500 mt-1 mr-3"></i>
                            <div>
                                <strong>死锁：</strong>线程相互等待对方释放资源，可能导致程序陷入死锁。
                            </div>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-exchange-alt text-red-500 mt-1 mr-3"></i>
                            <div>
                                <strong>上下文切换开销：</strong>频繁的线程上下文切换会带来性能开销。
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Section 3: Thread Creation -->
        <div class="content-card rounded-2xl shadow-xl p-8 md:p-12 mb-12">
            <h2 class="text-3xl font-bold mb-8 text-gray-800">
                <i class="fas fa-plus-circle text-purple-600 mr-3"></i>
                线程的创建与管理
            </h2>
            
            <div class="mb-8">
                <h3 class="text-2xl font-semibold mb-4 text-gray-700">创建线程的方式</h3>
                
                <div class="mb-6">
                    <h4 class="text-lg font-medium mb-3 text-gray-600">
                        <i class="fas fa-code text-purple-500 mr-2"></i>
                        继承 Thread 类
                    </h4>
                    <div class="code-block">
                        <pre><code>class MyThread extends Thread {
    @Override
    public void run() {
        System.out.println("Thread is running...");
    }
}

MyThread thread = new MyThread();
thread.start();</code></pre>
                    </div>
                </div>
                
                <div class="mb-6">
                    <h4 class="text-lg font-medium mb-3 text-gray-600">
                        <i class="fas fa-code text-purple-500 mr-2"></i>
                        实现 Runnable 接口
                    </h4>
                    <div class="code-block">
                        <pre><code>class MyRun